package com.far.game.xiuzhen.gm.web.api.admin;


import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.far.game.xiuzhen.common.database.entity.DictCharProp;
import com.far.game.xiuzhen.common.database.entity.User;

import com.far.game.xiuzhen.common.utils.RedisUtil;
import com.far.game.xiuzhen.gm.web.BaseController;
import com.far.game.xiuzhen.service.IUserService;
import com.far.game.xiuzhen.service.RedisService.RedisCacheData;
import com.far.tools.net.http.ReqParamWrapper;

import com.far.tools.net.http.transfer.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootVersion;
import org.springframework.core.SpringVersion;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mike
 * @since 2022-07-15
 */
@RestController
@RequestMapping(value = "/api/admin/test")
public class TestController extends BaseController {

    @Autowired
    private RedisCacheData redisCacheData;

    @Autowired
    RedisUtil redisUtil;

    /*
     * @description: 这个测试不要删除，一直没有找到问题
     * 无法收到?xxx=1 这样的参数 初步怀疑是NGINX做重定向时
     * 导致参数丢失
     * @author mike/Fang.J/Q184377367
     * @date 2022/8/13 23:50
    */
    @GetMapping(value = "test")
    public ResultData<String> test(@RequestParam(value = "tid") String tid ) {

        return ResultData.ok("测试"+tid.toString());
    }


    @GetMapping(value = "test2/{tid}")
    public ResultData<String> test2(@PathVariable(value = "tid") String tid ) {

        return ResultData.ok("测试"+tid.toString());
    }


//
//    @PostMapping(value = "test")
//    public ResultData<IPage<User>> test(@RequestBody ReqParamWrapper<User,String> userParam) {
//
//
//        IPage<User> producePage = new Page<>(userParam.getCurrent(),userParam.getSize());
////        LambdaQueryWrapper<User>queryWrapper=new LambdaQueryWrapper<>();
////        queryWrapper.eq(User::getUserName,userParam.getSearch().getUserName());
//        //第一种
////        IPage<User> page = iUserService.page(producePage,queryWrapper);
//        //第二种
////        IPage<User>  page = new LambdaQueryChainWrapper<>(iUserService.getBaseMapper())
////                .like(User::getUserName,userParam.getSearch().getUserName())
////
////                .page(producePage);
//        return ResultData.ok(null);
//    }


    @PostMapping(value = "test3")
    public ResultData<IPage<User>> test2(@RequestBody ReqParamWrapper<Map<String,Object>,String> userParam) {

//        userParam.getSearch().get("xxx");
//        IPage<User> producePage = new Page<>(1,1);
//        //第一种
//        IPage<User> page = iUserService.page(producePage);
//        //第二种
//        page = new LambdaQueryChainWrapper<>(iUserService.getBaseMapper()).eq(User::getUserName,"xx").page(producePage);
        return ResultData.ok(null);
    }


    @GetMapping(value = "redis-test")
    public ResultData<String>redisTest(@RequestParam String name , @RequestParam  int age){


        redisCacheData.cacheData();
        return ResultData.ok("OK");
    }

    @GetMapping(value = "get-redis-test")
    public ResultData<String>getRedisTest(){

        //userPartner:mike
        return ResultData.ok( redisUtil.get("xz_skills:10").toString());
    }












}

